#
# cfgtools.rb
#
# General tool for finding and accessing configuration file
# Configuration file may be placed in current folder or its location can
# be specified in %RUSALAD_CONFIG% environment variable
#

def get_config_value(name, default = nil)
  cfgfile = ENV["RUSALAD_CONFIG"]
  cfgfile = "rusalad.conf" unless cfgfile != nil && File.exists?(cfgfile)
  if cfgfile && File.exists?(cfgfile)
    config = YAML.load_file(cfgfile)
    return config[name] if config[name] != nil
  else
    raise "Config file 'rusalad.conf' was not found. Please ensure that it exists in current directory, or is pointed by RUSALAD_CONFIG environment variable which is '#{ENV["RUSALAD_CONFIG"]}' now"
  end
  e = ENV["RS_#{name}".upcase]
  return e if e
  return default
end
